oo::class create FileMenu {
    superclass AppMenu
    variable Menu Label NotebookObj Notebook

    constructor {menubar} {
        next $menubar file

        wm protocol . WM_DELETE_WINDOW [list [self object] quitApp]
    }

    method createMenu {} {
        foreach row {
            {command {New {} 0 newFile}}
            {command {Open C-o 0 openFile}}
            {command {Save C-s 0 saveFile}}
            {command {{Save As} {} 1 saveAsFile}}
            {command {Close C-q 1 closeFile}}
            {separator {}}
            {command {Quit {} 1 quitApp}}
        } {
           my createItem $row
        }
    }

    method ifNotebookEmpty? {} {
        return [expr {[$Notebook tabs] == {}}]
    }

    method newFile {} {
        $NotebookObj createNewContainer [$NotebookObj nextTabid [$Notebook index current]]
    }

    method openFile {} {
        $NotebookObj openFileAt [$Notebook index current]
    }

    method saveFile {} {
        $NotebookObj saveFile [$Notebook index current]
    }

    method saveAsFile {} {
        $NotebookObj saveAsFile [$Notebook index current]
    }

    method closeFile {} {
        $NotebookObj closeContainer [$Notebook index current]
        if [my ifNotebookEmpty?] {
            my quitApp
        }
    }

    method quitApp {} {
        $NotebookObj destroy
        exit
    }

    method update {textWidget langObj} {
        if ![$textWidget edit modified] {
            $Menu entryconfigure 2 -state disable
        } else {
            $Menu entryconfigure 2 -state normal
        }
    }
}